function ajax(opction) {
    let { url, method = 'GET', data, type, sussces, error } = opction;
    const xhr = new XMLHttpRequest();
    const newData = [];
    for (const key in data) {
        newData.push(`${key}=${data[key]}`);
    }

    data = newData.join('&')
    method === 'GET' ? url += `?${data}` : url;

    xhr.open(method, url);

    xhr.onreadystatechange = () => {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                sussces(type === 'json' ? JSON.parse(xhr.responseText) : xhr.responseText);
            } else {
                error(new Error(xhr.responseText));
            }
        }
    }

    if (method === 'POST') {
        xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    }

    xhr.send(method === 'POST' ? data : null);

}